<?php
if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class Peserta extends CI_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->library('parser');
		$this->load->model('m_peserta');
	}

	public function index() {
		//tetapkan meta deskripsi
		$this->parser->set_desc('Website Jamkesda Kabupaten Penajam Paser Utara');
		//Memanggil nilai dari form pencarian
		$kecamatan 	= $this->input->post('kecamatan');
		$desa 			= $this->input->post('desa');

		$this->load->library('paging'); //Load library "paging"
		if($this->input->post('submit') != ''){
			if($kecamatan != '' && $desa == ''){
				$config['sql']	= $this->m_peserta->get_per_kecamatan($kecamatan);	//Query SQL - bukan array lho ya...
			}else if($kecamatan != '' && $desa != ''){
				$config['sql']	= $this->m_peserta->get_per_desa($desa);	//Query SQL - bukan array lho ya...
			}else{
				$config['sql']	= $this->m_peserta->get();	//Query SQL - bukan array lho ya...
			}
		}else{
	    $config['sql']		= $this->m_peserta->get();	//Query SQL - bukan array lho ya...
	  }

    $config['per_page'] 				= 10;  //jumlah item tiap halaman
    $data = $this->paging->create_pagination($config);
	    
		$data['kecamatan'] 	= $this->m_peserta->getKecamatan();
		$data['kec']				= $kecamatan;
		if($kecamatan != ''){
			$data['desa']			= $this->m_peserta->getDesa($kecamatan);
			$data['ds']				= $desa;
		}else{
			$data['ds']				= $desa;
		}
		// Load the template from the views directory
		$this->parser->theme('front','peserta/index', $data);
	}

	public function desa() {
		$id_kecamatan 	= $this->input->post('id_kecamatan');
		$data['desa'] 	= $this->m_peserta->getDesa($id_kecamatan);

		// Load the template from the views directory
		$this->parser->no_theme('front','peserta/ajax_desa', $data);
	}
}
